package com.zongzi.stock.global;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * Created by Dell on 2017/5/11.
 */

public class URLs {

    /**
     * 搜索股票是否存在，搜索中文获得股票代码，或者搜索前面几位代码获得相关股票
     * baidu的url编码方式是gb2312
     * https://gupiao.baidu.com/api/search/stockquery?from=pc&os_ver=1&cuid=xxx&vv=3.2&format=json&query_content=0
     * @param content
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String searchStock(String content) throws UnsupportedEncodingException {
        String result = URLEncoder.encode(content, "UTF-8");
        return "https://gupiao.baidu.com/api/search/stockquery?from=pc&os_ver=1&cuid=xxx&vv=3.2&format=json&query_content="
                + result;
    }

    /**
     * 获得分时曲线数据
     * https://gupiao.baidu.com/api/stocks/stocktimeline?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=sz300033&timestamp=1494509030000
     * @param stockNum
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String getMinData(String stockNum) {
        return "https://gupiao.baidu.com/api/stocks/stocktimeline?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code="
                + stockNum + "&timestamp=" + System.currentTimeMillis();
    }

    /**
     * 获得一天最高，最低等数据
     * https://gupiao.baidu.com/api/rails/stockbasicbatch?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=
     * sz300033&timestamp=1495683737098
     * @param stockNum
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String getDailyData(String stockNum) {
        return "https://gupiao.baidu.com/api/rails/stockbasicbatch?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code="
                + stockNum + "&timestamp=" + System.currentTimeMillis();
    }

    /**
     * 获得多个一天最高，最低等数据
     * https://gupiao.baidu.com/api/rails/stockbasicbatch?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=
     * sz300033%2Csz002050%2Csh000001&timestamp=1495687187708
     * %2C 解码为：,
     * @param stockNums
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String getDailyDatas(List<String> stockNums) {
        StringBuffer stock = new StringBuffer();
        for (int i=0;i< stockNums.size();i++){
            if(i != 0){
                stock.append("%2C");
            }
            stock.append(stockNums.get(i));
        }
        return "https://gupiao.baidu.com/api/rails/stockbasicbatch?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code="
                + stock + "&timestamp=" + System.currentTimeMillis();
    }
}
